package mammuthus.web.util

import com.webdm.common.tools.StringUtil

/**
 * Created by fengbingjian on 15/3/27 09:52.
 */
object ShellUtil {

  var programsDir = "/data/web/applications"
  val commonShell =
    """
      |
      |cd /data/web/applications/%appName%/
      |
      |echo "[`date`] %appName% %action% %param%"
      |
      |./bin/deploy.sh %action% %param%
      |
      |pid=`cat ./current/application.pid`
      |
      |echo "[`date`] 进程信息"
      |ps -ef|grep $pid|grep -v grep
      |
      |echo -e "\n\n"
      |
    """.stripMargin


  def getShell(appName: String, action: String, param: String):String = {

    if("log" == action){
      s"tail -n 200 /data/web/applications/${appName}/current/logs/csdn_search.log"
    }else{
      commonShell.replace("%appName%", StringUtil.toString(appName))
        .replace("%action%", StringUtil.toString(action))
        .replace("%param%", StringUtil.toString(param))
    }



  }
}
